package com.bw.controller;

import com.bw.entity.User;
import com.bw.mapper.UserMapper;
import org.spring.kun.common.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ListController {

    @Autowired
    UserMapper userMapper;

    @RequestMapping("/list.do")
    public String list(Model model, HttpServletRequest request){

       List<User> list =  userMapper.listAll();

        model.addAttribute("list",list);

        User userFromRequest = TokenUtils.getLoginUserFromRequest(request, User.class);
        model.addAttribute("nickName",userFromRequest.getNickName());
        model.addAttribute("avatarUrl",userFromRequest.getAvatarUrl());

        return "list";
    }
}
